////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Microsoft Corporation.  All rights reserved.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "tinyhal.h"
#include "..\..\..\..\..\DeviceCode\Targets\Native\FM3\DeviceCode\FM3.h"
//#include "mcu.h"

#define LCD_ADDRESS	(*(volatile unsigned char*)0x61000000)
#define LCD_VALUE	(*(volatile unsigned char*)0x61000002)

void P8_Initialize(void)
{
	// Reset
	FM3_GPIO->ADE &= 0xFFF7;		// P13 NOT Analog
	FM3_GPIO->PFR1 &= 0xFFF7;	// P13 GPIO
	FM3_GPIO->DDR1 |= 0x0008;	// P13 output
}

void LCD_nRESET(int n)
{
	if (n)
		FM3_GPIO->PDOR1 |= 0x0008;
	else
		FM3_GPIO->PDOR1 &= 0xFFF7;
}

void P8_LCD_cmd(volatile unsigned short index)
{
	LCD_ADDRESS = (unsigned char)(index >> 8);
	LCD_ADDRESS = (unsigned char)(index >> 0);
	return;
}

void P8_LCD_dat(volatile unsigned short data)
{
	LCD_VALUE = (unsigned char)(data >> 8);
	LCD_VALUE = (unsigned char)(data >> 0);
}

unsigned short P8_LCD_read_dat(volatile unsigned short index)
{
	volatile unsigned short data;
	LCD_ADDRESS = (unsigned char)(index >> 8);
	LCD_ADDRESS = (unsigned char)(index >> 0);
	data = (unsigned short)LCD_VALUE;
	data = (data << 8) + (unsigned short)LCD_VALUE;
	return data;
}
//--//

